package com.example.javawebdemo.command;

import com.example.javawebdemo.dao.DAOFactory;
import com.example.javawebdemo.dao.ProductDAO;
import com.example.javawebdemo.models.Product;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.util.List;


/*
3.命令模式 (Command Pattern) - 解耦ProductServlet
 */

// ListProductsCommand.java
public class ListProductsCommand implements ProductCommand {
    public void execute(HttpServletRequest request, HttpServletResponse response) throws Exception {
        ProductDAO dao = DAOFactory.getProductDAO();
        List<Product> products = dao.getAllProducts();
        request.setAttribute("products", products);
        request.getRequestDispatcher("products.jsp").forward(request, response);
    }
}
